package com.szc.demo01.timer;

import com.szc.demo01.pojo.Schdule;
import com.szc.demo01.service.SchduleService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Component
public class SchduleTimer {

    @Resource
    private SchduleService schduleService;

    /**
     * 判断日程是否过期 每天凌晨0点刷新
     */
    @Scheduled(cron = "0 0 * * * ?")
    public void start(){
        List<Schdule> list = this.schduleService.list();
        Date date = new Date(System.currentTimeMillis());
        for(Schdule schdule: list){
            if(date.getTime()-schdule.getCreateTime().getTime()>schdule.getValidity()*24*60*60*1000){
                schdule.setIsFinish(2);
                schduleService.updateById(schdule);
            }
        }
    }

}
